import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'main.dart';
import 'my_route.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String shareLocal = '';

  @override
  void initState() {
    initLocalState();

  }

  void initLocalState() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('videoUrl', 'https://sample-videos.com/video123/flv/240/big_buck_bunny_240p_10mb.flv');

    shareLocal = prefs.getString('videoUrl')!;
  }

  void _incrementCounter() async{
    print('start second page from _incrementCounter');
    var resl = await myRoute.push(name: MyRoute.videoListPage, args: 'hello form mainPage');
    print('_incrementCounter: $resl');

    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(shareLocal),
            Text(
              '_MyHomePageState 显示',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}